package com.qf.test;

import java.lang.reflect.Field;

/**
 * @author zdl
 * @date 2025/1/11
 */
public class Demo4 {
    public static void main(String[] args) throws NoSuchFieldException, InstantiationException, IllegalAccessException {
        //获取属性
        Class<Animal> ac = Animal.class;
        Field field = ac.getDeclaredField("name");
        Animal animal = ac.newInstance();
        field.set(animal,"田七");
        Field field1 = ac.getDeclaredField("age");
        field1.setAccessible(true);
        field1.set(animal,99);
        System.out.println(animal);
    }
}
